<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>学生列表</title>
    <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
</head>
<body>
<div class="container mt-4">
    <h2>学生列表</h2>
    
    <form class="form-inline mb-3" th:action="@{/student/list}" method="get">
        <input type="text" class="form-control mr-2" name="name" th:value="${name}" placeholder="学生姓名">
        <button type="submit" class="btn btn-primary">搜索</button>
        <a th:href="@{/student/add}" class="btn btn-success ml-2">添加学生</a>
    </form>
    
    <table class="table table-striped">
        <thead>
        <tr>
            <th>学号</th>
            <th>姓名</th>
            <th>性别</th>
            <th>专业</th>
            <th>电话</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="student : ${pageInfo.list}">
            <td th:text="${student.studentNo}"></td>
            <td th:text="${student.name}"></td>
            <td th:text="${student.gender} == 1 ? '男' : '女'"></td>
            <td th:text="${student.major}"></td>
            <td th:text="${student.phone}"></td>
            <td>
                <a th:href="@{'/student/edit/' + ${student.id}}" class="btn btn-sm btn-primary">编辑</a>
                <a th:href="@{'/student/delete/' + ${student.id}}" class="btn btn-sm btn-danger" 
                   onclick="return confirm('确定要删除吗？')">删除</a>
            </td>
        </tr>
        </tbody>
    </table>
    
    <nav>
        <ul class="pagination">
            <li class="page-item" th:classappend="${pageInfo.isFirstPage} ? 'disabled' : ''">
                <a class="page-link" th:href="@{/student/list(page=1, size=${pageInfo.pageSize}, name=${name})}">首页</a>
            </li>
            <li class="page-item" th:classappend="${!pageInfo.hasPreviousPage} ? 'disabled' : ''">
                <a class="page-link" th:href="@{/student/list(page=${pageInfo.prePage}, size=${pageInfo.pageSize}, name=${name})}">上一页</a>
            </li>
            
            <li th:each="pageNum : ${pageInfo.navigatepageNums}" 
                class="page-item" th:classappend="${pageInfo.pageNum == pageNum} ? 'active' : ''">
                <a class="page-link" 
                   th:href="@{/student/list(page=${pageNum}, size=${pageInfo.pageSize}, name=${name})}" 
                   th:text="${pageNum}"></a>
            </li>
            
            <li class="page-item" th:classappend="${!pageInfo.hasNextPage} ? 'disabled' : ''">
                <a class="page-link" th:href="@{/student/list(page=${pageInfo.nextPage}, size=${pageInfo.pageSize}, name=${name})}">下一页</a>
            </li>
            <li class="page-item" th:classappend="${pageInfo.isLastPage} ? 'disabled' : ''">
                <a class="page-link" th:href="@{/student/list(page=${pageInfo.pages}, size=${pageInfo.pageSize}, name=${name})}">末页</a>
            </li>
        </ul>
    </nav>
</div>

<script th:src="@{/js/bootstrap.bundle.min.js}"></script>
</body>
</html>